<template>
    <div class="box">
      <div id="login_box">
        <h2>用户登录</h2>
        <div id="form">
          <div id="input_box1">
            <i class="fa fa-user" aria-hidden="true"></i>
            <el-input
              placeholder="请输入账号"
              v-model="input_id"
              show-word-limit
              maxlength="12"
              minlength="4"
              :suffix-icon="name_law"
              clearable>
            </el-input>
          </div>
          <div id="input_box2">
            <i class="fa fa-key" aria-hidden="true"></i>
            <el-input
              placeholder="请输入密码"
              v-model="input_password"
              clearable
              show-password>
            </el-input>
          </div>
        </div>

        <!--<button>登陆</button>-->
        <el-button :plain="true" @click="login(input_id,input_password)">登陆</el-button>
        <br />
        <div id="Sign">
          <router-link :to="{name:'Regist'}">没有账号?点我注册</router-link>
        </div>
      </div>
      <router-view></router-view>
      <mr ref="tip"></mr>
    </div>
</template>

<script>
import mr from '../base/MessageResult'

export default {
  name: 'Login',
  components: {mr},
  data () {
    return {
      input_id: '',
      input_password: '',
      name_law: '',
      info: ''
    }
  },
  methods: {
    check_userInfo: function (id, password) {
      if (/^[\u2E80-\u9FFF]+$/.test(id)) {
        this.$refs.tip.open_fail('账号不允许出现中文')
        return false
      }
      if (this.check_param(id) && this.check_param(password)) {
        return true
      } else {
        return false
      }
    },
    check_param: function (param) {
      if (param.length > 12) {
        this.$refs.tip.open_fail('账号或密码长度不能大于12')
        return false
      } else if (param.length < 4) {
        this.$refs.tip.open_fail('账号或密码长度不能小于4')
        return false
      } else {
        return true
      }
    },
    login: function (id, password) {
      if (!this.check_userInfo(id, password)) {
        return false
      }
      var that = this
      this.axios.get('http://localhost:8080/linearAlgebra/judge?id=' + id + '&password=' + password)
        .then(function (response) {
          if (response.data.length !== 0) {
            that.$refs.tip.open_success('登陆成功')
            if (response.data.role === 1) {
              sessionStorage.setItem('id', id)
              that.$router.push('/admin')
            } else {
              that.$router.push('/index')
            }
          } else {
            that.$refs.tip.open_fail('用户名或密码错误')
          }
        })
    }
  }

}

</script>

<style scoped>
  *{
    padding: 0px;
    margin: 0px;
  }
  .box{
    position : absolute;
    width : 100%;
    height : 100%;
    border: 1px solid transparent;
    background-image: url('../../../static/img/background8.png');
    background-size: contain;
    background-repeat: no-repeat;
  }
  #login_box{
    width: 20%;
    height: 350px;
    background:#3a8ee663;
    /*background:#409EFF;*/
    float: right;
    margin-top: 8%;
    margin-right: 10%;
    text-align: center;
    border-radius: 10px;
    padding: 50px 50px;
  }
  .in{
    height: 23px;
  }
  #login_box h2{
    color: #fff;
    margin-top: 3%;
  }
  #login_box #form #input_box1,#input_box2{
    margin-top: 15%;
    height: 40px;
  }
  #login_box #form #input_box i{
    color: #fff;
  }
  #login_box #form #input_box input{
    border:0;
    width: 60%;
    font-size: 15px;
    color: #fff;
    background: #ffffff00;
    border-bottom: 2px solid#fff;
    padding: 5px 10px;
    margin-top: 10px;
  }
  #login_box button{
    margin-top: 50px;
    width: 40%;
    height: 30px;
    border-radius: 10px;
    border: 0;
    color: #fff;
    font-size: 15px;
    background-image: linear-gradient(to top, #30324d 0%, #5f6298 100%);
  }
  #login_box #Sign{
    margin-top: 15px;
    margin-left: 50%;
  }
  #login_box #Sign a{
    color: rgba(0, 0, 0, 0.55)
  }
</style>
